﻿using System;
using System.Collections;
using System.Linq;
using System.Text;
using rock.Model;
using rock.DAL;
using System.Data.SqlClient;

namespace rock.BLL
{
    class BllUSER_ACCOUNT
    {
        DalUSER_ACCOUNT dalUSER_ACCOUNT = new DalUSER_ACCOUNT();
        DalUSER_AUTHO dalUSER_AUTHO = new DalUSER_AUTHO();
        public void updateOrAddUser(ModelUSER_ACCOUNT _userAccount, ModelUSER_AUTHO _userAutho)
        {

            Hashtable sqlParamInfo = new Hashtable ();

            if (dalUSER_ACCOUNT.Exists(_userAccount.ACCOUNT))
            {
             SqlParamInfo info =   dalUSER_ACCOUNT.Update(_userAccount);
             sqlParamInfo.Add(info.sql, info.parameters);
            }
            else
            {
                SqlParamInfo info = dalUSER_ACCOUNT.Add(_userAccount);
                sqlParamInfo.Add(info.sql, info.parameters);
            }

            if (dalUSER_AUTHO.Exists(_userAccount.ACCOUNT))
            {
                SqlParamInfo info = dalUSER_AUTHO.Update(_userAutho);
                sqlParamInfo.Add(info.sql, info.parameters);
            }
            else
            {
                SqlParamInfo info = dalUSER_AUTHO.Add(_userAutho);
                sqlParamInfo.Add(info.sql, info.parameters);
            }

            DbHelperSQL.ExecuteSqlTran(sqlParamInfo);
        }

        public void deleteUser(String account) {
            Hashtable sqlParamInfo = new Hashtable();

            SqlParamInfo info = dalUSER_ACCOUNT.Delete(account);
            sqlParamInfo.Add(info.sql, info.parameters);

            SqlParamInfo info2 = dalUSER_AUTHO.Delete(account);
            sqlParamInfo.Add(info2.sql, info2.parameters);
            DbHelperSQL.ExecuteSqlTran(sqlParamInfo);

        }

    }
}
